const knex = require('../db/knex');

class OrderDetailModel {
  static async addOrderDetails(orderDetails) {
    await knex('order_details').insert(orderDetails);
  }

  static async getOrderDetails(orderId) {
    return await knex('order_details')
      .join('items', 'order_details.item_id', '=', 'items.item_id')
      .select(
        'order_details.detail_id',
        'items.product_name',
        'order_details.quantity',
        'order_details.price'
      )
      .where({ 'order_details.order_id': orderId });
  }
}

module.exports = OrderDetailModel;